import { reqAddMenuOrFeature, reqMenuList, reqRemoveMenuOrFeature, reqUpdateMenuOrFrature } from "@/api/acl/menu"

const actions = {
    // 发送获取菜单数据的action
    async getMenuList({ commit }) {
        const result = await reqMenuList()
        if (result.code === 20000) {
            commit('GETMENULIST', result.data.children)
        }
    },
    // 发送添加菜单|功能的action
    async addMenuOrFeature(_, data) {
        const result = await reqAddMenuOrFeature(data)
        if (result.code === 20000) {
            return 'ok'
        }
        return Promise.reject()
    },
    // 发送修改菜单|功能的action
    async updateMenuOrFrature(_, data) {
        const result = await reqUpdateMenuOrFrature(data)
        if (result.code === 20000) {
            return 'ok'
        }
        return Promise.reject()
    },
    // 发送删除菜单|功能的action
    async removeMenuOrFeature(_, id) {
        const result = await reqRemoveMenuOrFeature(id)
        if (result.code === 20000) {
            return 'ok'
        }
        return Promise.reject()
    }
}
const mutations = {
    GETMENULIST(state, menuList) {
        state.menuList = menuList
    }
}
const state = {
    menuList: []
}

export default {
    namespaced: true,
    actions,
    mutations,
    state
}